﻿using DroidLord.Task;
using DroidLord.Util;
using Newtonsoft.Json.Linq;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace DroidLord.app.dy.data
{
    class DYVideoInfo
    {
        public bool isParseOk = false;
        //
        public string awemeId = "";
        //
        public string desc = "";
        //
        public string creatTime = "";
        //
        public string playAddr = "";

        public string duration = "";

        public string nickName = "";

        public string diggCount = "0";

        public string playCount = "0";
        public string commentCount = "0";
        

        private static string getValue(JObject userinfoobj, string key)
        {
            try
            {
                return userinfoobj[key].ToString();
            }
            catch (Exception eee)
            {
                // MessageBox.Show(eee.ToString());
            }
            return "";
        }
        public static DYVideoInfo parseData(string userinfo)
        {
            //
            DYVideoInfo userInfo = new DYVideoInfo();
            string statusCode = JObject.Parse(userinfo)["status_code"].ToString();
            if (statusCode.Equals("0"))
            {
                userInfo.isParseOk = true;
                JArray jarray = JArray.Parse(JObject.Parse(userinfo)["item_list"].ToString());
                int len = jarray.Count;

                if(len>0)
                {
                    JObject myobj = JObject.Parse(jarray[0].ToString());
                    userInfo.awemeId = getValue(myobj, "aweme_id");
                    userInfo.desc = getValue(myobj, "desc");
                    userInfo.creatTime = MyUtils.ConvertStringToDateTime(getValue(myobj, "create_time"));
                    string author = getValue(myobj, "author");
                    if(!author.Equals(""))
                    {
                        JObject authoObj = JObject.Parse(author);
                        userInfo.nickName = getValue(authoObj, "nickname");
                    }

                    string urlListString = myobj["video"]["play_addr"]["url_list"].ToString();
                    string awemeid = myobj["aweme_id"].ToString();
                    JArray videoUrlList = JArray.Parse(urlListString);
                    string videostring = videoUrlList[0].ToString();
                    userInfo.playAddr = videostring;
                    userInfo.duration =Convert.ToInt32( myobj["video"]["duration"].ToString())/1000+"秒";
                    userInfo.diggCount= myobj["statistics"]["digg_count"].ToString();
                    userInfo.commentCount = myobj["statistics"]["comment_count"].ToString();
                }

               
            }

            return userInfo;
        }
    }
}
